import common.CommonFunction;
import common.Mask;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

[Embed(source="/images/success.png")]private var successIcon:Class;
[Embed(source="/images/error.png")]private var errorIcon:Class;
[Embed(source="/images/question.png")]private var questionIcon:Class;

public var infoObject:Object;

public function onCreationComplete():void
{
	infoObject = new Object();
	infoObject["date"] = new Date();
		
	getCustomerProblems.send(infoObject);
	Mask.show(CommonFunction.getMessages('Please Wait..'));
}

public var customerXML:XML;
public var customerList:ArrayCollection;
public function onSuccess(event:ResultEvent):void
{
	customerXML = event.result as XML;
	customerList = new ArrayCollection();
	for each(var obj:Object in customerXML.record)
	{		
		customerList.addItem({select:true, col1:obj.reqnumber, col2:obj.custname,
			col3:obj.mobileno, col4:obj.narration,col5:obj.date,col6:obj.status,col7:obj.custid});	
	}
	customerDetailsGrid.dataProvider=customerList;
		
	Mask.close();
}

public function onFailure(event:FaultEvent):void
{
	Mask.close();
	Alert.show(event.message + "");
}

public var selectedRecords:ArrayCollection;
public function custissue():void
{	
	selectedRecords = new ArrayCollection();
	
	for each (var obj:Object in customerDetailsGrid.dataProvider)
	{
		if(obj.select==true)
		{
			selectedRecords.addItemAt(obj.col7,0);
			selectedRecords.addItemAt(obj.col3,1);	
		}
	}
	if(customerList.length==0)
	{
		Alert.show(CommonFunction.getMessages('selectARecord'), CommonFunction.getMessages('error'), 0, null, null);	
	}
	else
	{
		Alert.show(CommonFunction.getMessages('areyousure'), CommonFunction.getMessages('confirm'), (Alert.YES|Alert.NO), null, 
			onValidation);		
	}
}
public function onValidation(event:CloseEvent):void
{	
	if(event.detail==Alert.YES)
	{		
		infoObject = new Object();	
		infoObject["date"] = new Date();
		infoObject["customerissue"] = selectedRecords;
		Mask.show(CommonFunction.getMessages('Please Wait.......'));	
		updateissues.send(infoObject);
	}	
}